<template>
  <div class="frozen_list bg-gray">
    <div class="bg-white">
      <div class="w1200">
        <BackBar :backTitle="$t('nav.wallet')"></BackBar>
        <h3 class="title">{{$t('frozenList.frozenList0')}}</h3>
      </div>
    </div>

    <div class="w1200 mt_20">
      <el-table :data="txListData" stripe border>
        <el-table-column :label="$t('tab.tab1')" align="center">
          <template slot-scope="scope"><span>{{scope.row.rank}}</span></template>
        </el-table-column>
        <el-table-column :label="$t('tab.tab7')" align="center" min-width="150">
          <template slot-scope="scope">
            <!-- <span class="click" @click="toUrl('transferInfo',scope.row.transactionId)">{{scope.row.transactionId}}</span> -->
            <span class="click">{{scope.row.transactionId}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" :label="$t('tab.tab5')" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.timeStamp}}</span>
            </template>
        </el-table-column>
        <el-table-column prop="values" :label="$t('tab.tab6')" align="center">
            <template slot-scope="scope">
              <span>{{scope.row.assetAmount}}</span>
            </template>
        </el-table-column>
      </el-table>
      <!-- <div class="pages">
        <div class="page-total">
          {{$t('public.display')}} {{pageIndex-1 === 0 ? 1 : (pageIndex-1) *pageSize}}-{{pageIndex*pageSize}}
          {{$t('public.total')}} {{pageTotal}}
        </div>
        <el-pagination @current-change="frozenListPages" class="fr" background
                       v-show="pageTotal>pageSize"
                       :page-size=pageSize
                       layout=" prev, pager, next, jumper"
                       :total=pageTotal>
        </el-pagination>
      </div> -->
    </div>
  </div>
</template>

<script>
  import moment from 'moment'
  import {timesDecimals, getLocalTime, superLong, addressInfo} from '@/api/util'
  import BackBar from '@/components/BackBar'
  import axios from 'axios'

  export default {
    data() {
      return {
        txListData: [],//锁定列表
        pageIndex: 1, //页码
        pageSize: 10, //每页条数
        pageTotal: 0,//总页数
        addressInfo: [], //账户信息

      };
    },
    created() {
      this.addressInfo = addressInfo(1);
      setInterval(() => {
        this.addressInfo = addressInfo(1);
      }, 500);
    },
    mounted() {
      if (this.$route.query.accountInfo) {
        this.getTxListByAddress(this.addressInfo.address);
      }
    },
    components: {
      BackBar
    },
    methods: {

      /**
       * 获取地址的锁定列表
       * @param chainId
       * @param assetId
       * @param address
       * @param pageIndex
       * @param pageSize
       **/
      getTxListByAddress(address_now_select) {
        var params = {
            address: address_now_select,
            visible: true
        }
        this.$post('/wallet/getaccount', 'getAccountFreezes', params)
          .then((response) => {
            // console.log(response);
            if (response.delegate) {
              for (let item of response.delegate) {
                  item.timeStamp = moment(getLocalTime(item.timestamp)).format('YYYY-MM-DD HH:mm:ss');
                  item.transactionId = item.delegate_address;
                  item.assetAmount = Number(item.delegate_count / 1000000).toFixed(3);
                  item.rank = item.rank;
              }
              this.pageTotal = response.delegate.length;
              this.txListData = response.delegate;
            }
          })
          .catch((error) => {
            console.log("getAccountTxs:" + error);
          });

      },

      /**
       * 分页功能
       * @param val
       */
      frozenListPages(val) {
        this.pageIndex = val;
        this.getTxListByAddress(this.addressInfo.address, this.pageIndex);
      },

      /**
       * 连接跳转
       * @param name
       * @param param
       */
      toUrl(name, param) {
        //console.log(name)
        this.$router.push({
          name: name,
          query: {'hash': param}
        })
      },

    }
  }
</script>

<style scoped>

</style>
